<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  xmlns:l="clr-namespace:UIControls" >
    
  <SolidColorBrush x:Key="SearchTextBox_Background" Color="White" />
  <SolidColorBrush x:Key="SearchTextBox_Foreground" Color="Black" />
  <LinearGradientBrush x:Key="SearchTextBox_Border" StartPoint="0,0" EndPoint="0,1">
    <GradientStop Color="#FFABADB3" Offset="0.05" />
    <GradientStop Color="#FFE2E3EA" Offset="0.07" />
    <GradientStop Color="#FFE4E9EF" Offset="1" />
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="SearchTextBox_BorderMouseOver" StartPoint="0,0" EndPoint="0,1">
    <GradientStop Color="#FF5C97C1" Offset="0.05" />
    <GradientStop Color="#FFB9D7EB" Offset="0.07" />
    <GradientStop Color="#FFC7E2F1" Offset="1" />
  </LinearGradientBrush>
  <SolidColorBrush x:Key="SearchTextBox_SearchIconBorder" Color="White" />
  <SolidColorBrush x:Key="SearchTextBox_SearchIconBackground" Color="White" />
  <LinearGradientBrush x:Key="SearchTextBox_SearchIconBorder_MouseOver" StartPoint="0,0" EndPoint="0,1" >
    <GradientStop Color="#FFFFFFFF" Offset="0" />
    <GradientStop Color="#FFE5F4FC" Offset="1" />
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="SearchTextBox_SearchIconBackground_MouseOver" StartPoint="0,0" EndPoint="0,1" >
    <GradientStop Color="#FFE7F5FD" Offset="0" />
    <GradientStop Color="#FFD2EDFC" Offset="0.5" />
    <GradientStop Color="#FFB6E3FD" Offset="0.51" />
    <GradientStop Color="#FF9DD5F3" Offset="1" />
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="SearchTextBox_SearchIconBorder_MouseDown" StartPoint="0,0" EndPoint="0,1" >
    <GradientStop Color="#FFFFFFFF" Offset="0" />
    <GradientStop Color="#FFE5F4FC" Offset="1" />
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="SearchTextBox_SearchIconBackground_MouseDown" StartPoint="0,0" EndPoint="0,1" >
    <GradientStop Color="#FFE7F5FD" Offset="0" />
    <GradientStop Color="#FFD2EDFC" Offset="0.5" />
    <GradientStop Color="#FFB6E3FD" Offset="0.51" />
    <GradientStop Color="#FF9DD5F3" Offset="1" />
  </LinearGradientBrush>
  <SolidColorBrush x:Key="SearchTextBox_LabelTextColor" Color="Gray" />

  <Style x:Key="{x:Type l:SearchTextBox}" TargetType="{x:Type l:SearchTextBox}">
    <Setter Property="Background" Value="{StaticResource SearchTextBox_Background}" />
    <Setter Property="BorderBrush" Value="{StaticResource SearchTextBox_Border}" />
    <Setter Property="Foreground" Value="{StaticResource SearchTextBox_Foreground}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="LabelText" Value="Search" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="LabelTextColor" Value="{StaticResource SearchTextBox_LabelTextColor}" /> 
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type l:SearchTextBox}">
          <Border x:Name="Border"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}">
            <Grid x:Name="LayoutGrid">
                  <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
                  <ScrollViewer Margin="2" x:Name="PART_ContentHost" Grid.Column="0" VerticalAlignment="Center"/>
                  <Label x:Name="LabelText"
                         Margin="2"
                         Grid.Column="0"
                         Foreground="{Binding RelativeSource={RelativeSource TemplatedParent},
                                              Path=LabelTextColor}"
                         Content="{Binding RelativeSource={RelativeSource TemplatedParent},
                                           Path=LabelText}"
                         Padding="2,0,0,0"
                         VerticalAlignment="Center"
                         FontStyle="Italic" />
                  <Border x:Name="PART_SearchIconBorder"
                          Grid.Column="2"
                          VerticalAlignment="Stretch"
                          HorizontalAlignment="Stretch"
                          BorderBrush="{StaticResource SearchTextBox_SearchIconBorder}"
                          >
                        <Image x:Name="SearchIcon"
                               Stretch="None"
                               Width="15"
                               Height="15" 
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Source="pack://application:,,,/SearchTextBox;component/Images/search.png" ToolTip="Click to search"/>
                   </Border>

                    <Border x:Name="PART_SpecifySearchType"
                          Grid.Column="1"
                          VerticalAlignment="Stretch"
                          HorizontalAlignment="Stretch"
                          BorderBrush="{StaticResource SearchTextBox_SearchIconBorder}"
                          >
                        <Image x:Name="SpecifySearchType"
                               Stretch="None"
                               Width="15"
                               Height="15" 
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Source="pack://application:,,,/SearchTextBox;component/Images/Key-Add.png" ToolTip="Choose section(s)"
                               
                               />
                    </Border>

                    <Border x:Name="PART_PreviousItem"
                        Grid.Column="3"
                        VerticalAlignment="Stretch"
                        HorizontalAlignment="Stretch"
                        BorderBrush="{StaticResource SearchTextBox_SearchIconBorder}">
                            <Image x:Name="PreviousIcon"
                           Stretch="None"
                           Width="15"
                           Height="15" 
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Source="pack://application:,,,/SearchTextBox;component/Images/Previous.png" ToolTip="Previous keyword(s)"
                       />
                    </Border>
                </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True" SourceName="LabelText">
                <Setter Property="Background" TargetName="LayoutGrid" Value="#F3F9F2" />
                <Setter Property="Cursor" Value="IBeam" />
            </Trigger>
            
            <Trigger Property="IsMouseOver" Value="False">
                <Setter Property="Background" TargetName="LayoutGrid" Value="#DCEED9" />
            </Trigger>

            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource SearchTextBox_BorderMouseOver}" />
            </Trigger>
              
            <Trigger Property="HasText" Value="True">
                <Setter Property="Visibility" TargetName="LabelText" Value="Hidden" />
            </Trigger> 
              
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="HasText" Value="True" />
              </MultiTrigger.Conditions>
              <Setter Property="Source"
                      TargetName="SearchIcon"
                      Value="pack://application:,,,/SearchTextBox;component/Images/clear.png" />
            </MultiTrigger>

          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>
